#include "stdafx.h"
#include "Texture.h"
#include "Engine.h"

Graphics::Texture::Texture()
{

}

Graphics::Texture::~Texture()
{

}

bool Graphics::Texture::Init(const std::string& aFileName)
{
	HRESULT hr;

	D3DXIMAGE_INFO texInfo;
	//hr = D3DXGetImageInfoFromFile(aFileName.c_str(), &texInfo);

	hr = D3DXCreateTextureFromFileEx(Engine::GetInstance()->GetDevice(), aFileName.c_str(), D3DX_DEFAULT, D3DX_DEFAULT,
		D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
		D3DX_DEFAULT, D3DX_DEFAULT, 0,
		&texInfo, NULL, &myTexture);
	if(FAILED(hr))
	{
		DL_CHK_CRITICAL(false, "Error loading texture");
		DL_INCREASETAB;
		DL_PRINT(ExtendedString("Filename: ") << aFileName);
		DL_PRINT(ExtendedString("hr = ") << hr);
		DL_DECREASETAB;
		return false;
	}

	mySize.x = static_cast<float>(texInfo.Width);
	mySize.y = static_cast<float>(texInfo.Height);

	return true;
}

IDirect3DTexture9* Graphics::Texture::GetTexture()
{
	return myTexture;
}

const Vector2f& Graphics::Texture::GetSize()
{
	return mySize;
}